import store from 'store'

const USER_STORAGE = 'user_storage'
const NETWORK_CARD = 'network_card_storage'
const USER_DOI = "doi"
const PRIVATE_KEY = "key"
const TOKEN = "token"

const BDStorageUtils = {

  //保存网卡信息
  saveNetworkCard(card) {
    store.set(NETWORK_CARD, card)
  },
  getNetworkCard() {
    return store.get(NETWORK_CARD) || {}
  },
  //{"doi":"", "key":"", "token":""}
  saveUsers(user) {
    store.set(USER_STORAGE, user)
  },
  login(doi, key, jws) {
    const userInfo = {}
    userInfo[USER_DOI] = doi
    userInfo[PRIVATE_KEY] = key
    userInfo[TOKEN] = jws
    this.saveUsers(userInfo)
  },
  getUsers() {
    return store.get(USER_STORAGE) || {}
  },
  getUser(doi) {
    const users = store.get(USER_STORAGE)
    if (users == null) {
      return null
    } else {
      return users[doi]
    }
  },
  logout() {
    store.remove(USER_STORAGE)
  }
}
export default BDStorageUtils

